package com.edu.flink;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.util.Collector;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author jpge
 * @since 2024-04-23
 */
public class ExplainTest {

    /**
     * 1. 对于DataStream执行计划
     * 2. 对于Table的执行计划
     *
     * @param args
     */
    public static void main(String[] args) {
        //1. 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment streamTableEnvironment = StreamTableEnvironment.create(env);

        //2.设置数据源
        List<Integer> list = new ArrayList<>();
        list.add(1);

        DataStream<Integer> stream = env.fromCollection(list)
                .flatMap(new FlatMapFunction<Integer, Integer>() {
                    @Override
                    public void flatMap(Integer integer, Collector<Integer> collector) throws Exception {
                        collector.collect(integer * 2);
                    }
                }).setParallelism(2);
        //打印DataStream执行计划
        System.out.println(env.getExecutionPlan());

//        //打印Table的执行计划
//        Table table = streamTableEnvironment.fromDataStream(stream);
//        System.out.println(streamTableEnvironment.ex());

    }

}
